from flask import Flask
from flask import render_template
from flask import request

app = Flask(__name__)


@app.route("/", methods=["GET", "POST"])
def index():
    error = None
    if request.method == "POST":
        un = request.form['un']
        pwd = request.form['pwd']
        if not un or not pwd:
            error = "用户名和密码必须填写"
        else:
            if un == "admin" and pwd == "123456":
                return "<h1>登录成功</h1>"
            else:
                error = "用户名或者密码错误"
    return render_template("login.html", error=error)


def main():
    app.run(debug=True)


if __name__ == '__main__':
    main()
